#include "compat.h"

/*
Wrapper for Win32 Sleep()/Linux nanosleep().
Inputs:
	-Time: Delay time in milliseconds.
*/
void _compat_sleep(u32 Time)
{
	#ifdef LINUX
		usleep(Time * 1000);
		//unsigned int i;
		//timespec t; //this is needlessly complicated -_-
		//for(i=0; i<Time; i++)
		//{
		//	t.tv_sec = 0;
		//	t.tv_nsec = 1000000;
		//	nanosleep(&t, NULL);
		//}
		//
		//for(i=0; i<Time; i++)
		//	usleep(1000);
	#else
		Sleep(Time);
	#endif
}

/* Wrapper for GetTickCount()/gettimeofday()
 * Returns: elapsed time in milliseconds.
 * Notes:
 * -The absolute value is undefined; use only for comparison.
 */
u64 _getticks()
{
	#ifdef LINUX
		struct timeval tv;
		if(gettimeofday(&tv, NULL))
			return 0LL;
		return (u64)((tv.tv_sec * 1000L) + (tv.tv_usec / 1000L));
	#else
		return GetTickCount();
	#endif
}
